﻿<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="utf-8" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System.IO.Compression" %>
<script language="c#" runat="server">
protected void Page_Load(object sender, EventArgs e)
{ 
	
	string fi = Request.Params["file"];
	if(string.IsNullOrEmpty(fi)) return;
	if(fi.ToLower()=="mootools-1.2-core.js") fi = "/template/plugins/mootools-1.2-core.js";
	if(fi.ToLower()=="mootools-1.2-more.js") fi = "/template/plugins/mootools-1.2-more.js";	
	fi = Server.MapPath(fi);
	if(!System.IO.File.Exists(fi)) return;
	
	string content="";
	using(System.IO.StreamReader oReader = new System.IO.StreamReader(fi)) 
	{ 
		content = oReader.ReadToEnd(); 
		oReader.Close(); 
	} 	
	Response.Write(content);
	
	string acceptEncoding = HttpContext.Current.Request.Headers["Accept-Encoding"];
	System.IO.Stream resStream = HttpContext.Current.Response.Filter;
	acceptEncoding = acceptEncoding.ToLower();
	if (acceptEncoding.ToLower().Contains("gzip"))
	{
		// gzip
		HttpContext.Current.Response.Filter = new GZipStream(resStream,
			CompressionMode.Compress);
		HttpContext.Current.Response.AppendHeader("Content-Encoding", "gzip");
	} else if (acceptEncoding.Contains("deflate") || acceptEncoding == "*")
	{
		// defalte
		HttpContext.Current.Response.Filter = new DeflateStream(resStream,
			CompressionMode.Compress);
		HttpContext.Current.Response.AppendHeader("Content-Encoding", "deflate");
	}
}	
	
	

</script>